efi_arch_allocate_mmap_buffer() allocates a buffer for the EFI memory map, and
for ARM it allocates a larger buffer than requested. This is done to account
for the increase in the map size that may occur when the allocation is made.
The previous code allocated a larger buffer, but did not adjust the size to
match. This caused the later call to GetMemoryMap() to fail with a
BUFFER_TOO_SMALL error, since the original, smaller size was used. This patch
changes the argument to efi_arch_allocate_mmap_buffer() to be a pointer to
UINTN, and the ARM version updates the size on a successful allocation.
The x86 version uses a different allocation method, so only the function
argument type is changed.
Also add decode of the BUFFER_TOO_SMALL error code to PrintErrMesg().
Signed-off-by: Roy Franz <roy.franz@linaro.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com> [ARM]
Acked-by: Jan Beulich <jbeulich@suse.com> [non-ARM]
{
}
-static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
+static void *__init efi_arch_allocate_mmap_buffer(UINTN *map_size)
{
void *ptr;
EFI_STATUS status;
+ UINTN map_size_alloc = *map_size + EFI_PAGE_SIZE;
- status = efi_bs->AllocatePool(EfiLoaderData, map_size + EFI_PAGE_SIZE, &ptr);
+ status = efi_bs->AllocatePool(EfiLoaderData, map_size_alloc, &ptr);
if ( status != EFI_SUCCESS )
return NULL;
+ *map_size = map_size_alloc;
return ptr;
}
}
-static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
+static void *__init efi_arch_allocate_mmap_buffer(UINTN *map_size)
{
place_string(&mbi.mem_upper, NULL);
- mbi.mem_upper -= map_size;
+ mbi.mem_upper -= *map_size;
mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);
if ( mbi.mem_upper < xen_phys_start )
return NULL;
case EFI_COMPROMISED_DATA:
mesg = L"Compromised data";
break;
+ case EFI_BUFFER_TOO_SMALL:
+ mesg = L"Buffer too small";
+ break;
default:
PrintErr(L"ErrCode: ");
DisplayUint(ErrCode, 0);
efi_bs->GetMemoryMap(&efi_memmap_size, NULL, &map_key,
&efi_mdesc_size, &mdesc_ver);
- efi_memmap = efi_arch_allocate_mmap_buffer(efi_memmap_size);
+ efi_memmap = efi_arch_allocate_mmap_buffer(&efi_memmap_size);
if ( !efi_memmap )
blexit(L"Unable to allocate memory for EFI memory map");